﻿using System;
using Example.Client.Capture;
using System.ServiceModel;
namespace Example
{
    [CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class CaptureServiceCallback : ICaptureServiceCallback, IDisposable
    {
        private readonly CaptureServiceClient _client;

        public CaptureServiceCallback()
        {
            _client = new CaptureServiceClient(new InstanceContext(this));
            _client.Subscribe(new Subscription { RequestAudio = true, RequestVideo = true });
        }
        public void Dispose()
        {
            _client.Unsubscribe();
            _client.Close();
        }

        public void OnMessage(string message)
        {
            Console.WriteLine(message);
        }

        public void OnFrame(FrameBase frame)
        {
            AudioFrame audioFrame;
            VideoFrame videoFrame;
            if ((audioFrame = (frame as AudioFrame)) != null)
                Console.WriteLine("a: {1}", frame.GetType().Name, audioFrame.Data.Length);
            else if ((videoFrame = (frame as VideoFrame)) != null)
                Console.WriteLine("v: {1}", frame.GetType().Name, videoFrame.Data.Length);
        }
    }
}
